---
--- Created by root.
--- DateTime: 17-11-20 上午11:48
---
local lfc = {}

function lfc.split(self, szFullString, szSeparator)

    local nFindStartIndex = 1
    local nSplitIndex = 1
    local nSplitArray = {}
    while true do
        local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
        if not nFindLastIndex then
            nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
            break
        end
        nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
        nFindStartIndex = nFindLastIndex + string.len(szSeparator)
        nSplitIndex = nSplitIndex + 1
    end
    return nSplitArray
end

function lfc.trim (self, s)
    return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

--生成唯一串，切记开启共享内存
function lfc.mt_sn()

    local arg,err = luashare:get("cfname")
    if not arg then
        local i,err = luashare:safe_add("cfname",1,3600)
    end
    local time = os.time()
    local cfname = luashare:incr("cfname",1)
    local sn_seed = time.."-"..cfname;
    local sn = ngx.hmac_sha1("枯藤老树昏鸦", sn_seed)
    return string.lower(string.gsub(sn,"(.)",function (x) return string.format("%02X",string.byte(x)) end))
end

function lfc.readfile(path)
    local file = io.open(path, "r")
    if file then
        local content = file:read("*a")
        io.close(file)
        return content
    end
    return nil
end

return lfc;